<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/9
 * Time: 16:46
 */

namespace App\Service;

use Illuminate\Support\Facades\DB;
class TicketService
{
    public static function get_ticket_type($where){
        $ticker_list = DB::table('ticket_user')
            ->leftJoin('tickets','ticket_user.ticket_id', '=', 'tickets.id')
            ->leftJoin('ticket_condition','ticket_condition.ticket_id', '=', 'tickets.id')
            ->where($where)
            ->select('tickets.*','ticket_user.id as ticket_user_id','ticket_user.state as ticket_user_state','ticket_condition.category_id','ticket_condition.brand_id')
            ->orderBy('ticket_user.id','desc')
            ->paginate(10);
        if(!$ticker_list){
            return  $ticker_list;
        }
        foreach($ticker_list as $k=>$v){
            $ticker_list[$k]->category_name = '';
            $ticker_list[$k]->brand_name = '';
           if(!empty($v->category_id)){
              $category_title =  DB::table('product_category')->where(['id'=>$v->category_id])->select('title')->first();
               $ticker_list[$k]->category_name = $category_title->title;
           }
            if(!empty($v->brand_id)){
                $brand_title =  DB::table('product_brand')->where(['id'=>$v->brand_id])->select('title_all')->first();
                $ticker_list[$k]->brand_name = $brand_title->title_all;
            }
        }
        return  $ticker_list;
    }
}